﻿using System;

using System.Collections.Generic;
using AdminHome.Models;
namespace AdminHome.FunctionalServices
{
    public static class AdminHomeServices
    {//Html integration services
        public static string getAllLocations()
        {
            var data = AdminHome.DatabaseServices.AdminHomeDatabaseMethods.getAllLocations();
            var writeThisAsHtml = "<table>";
            writeThisAsHtml += "<tr><td>0</td><td>1</td><td>2</td><td>3</td></tr>";
            var i = 0;
            while (i < data.Count)
            {
                writeThisAsHtml += "<tr><td>" + data[i][0] + "</td> <td>" + data[i][1] + "</td> <td>" + data[i][2] + "</td> <td>" + data[i][3] + "</td><td><input name=" + data[i][3] + " type=\"checkbox\"></input></td></tr>";
                i++;
            }

            writeThisAsHtml += "</table>";
            return writeThisAsHtml;
        }
        public static String getAccountId(String UserName)
        {
            var data = AdminHome.DatabaseServices.AdminHomeDatabaseMethods.getAccountId(UserName);
            return data;
        }
        public static String getShoppingCartID(String accountID)
        {
            var data = AdminHome.DatabaseServices.AdminHomeDatabaseMethods.getShoppingCartID(accountID);

            return data;
        }
        
        public static String displayAccountDetails(String UserName)
        {
            var data = MVCSiteJDG.Dao.DataAccess.Reader.readAccountDetails(UserName);
            var returnThis = " name = " + data[0] + "registration date" + data[1] + "last login" + data[2] + "email" + data[3];
            
            return returnThis;
        }
        
        public static String displayProductList(int minRange, int maxRange)
        {
            var data = MVCSiteJDG.Dao.DataAccess.Reader.getProductList(minRange, maxRange);
            var writeThisAsHtml = "<table>";
            writeThisAsHtml += "<tr><td>Image</td><td>Cat</td><td>Product</td><td>name</td><td>description</td><td>indate</td></tr>";
            var i = 0;
            while (i < data.Count)
            {
                writeThisAsHtml += "<tr><td>" + data[i][3] + "</td><td>"+ data[i][5]  +"<td></td>" + data[i][6] + "</td> <td>" + data[i][0] + "</td> <td>" + data[i][1] + "</td> <td>" + data[i][4] + "</td><td><input name=" + data[i][7] + " type=\"checkbox\"></input></td></tr>";
                i++;
            }

            writeThisAsHtml += "</table>";
            return writeThisAsHtml;

        }

        public static String displayShoppingCart(String shoppingCartID)
        {
            var data = MVCSiteJDG.Dao.DataAccess.Reader.getShoppingCartItemsProdIds(shoppingCartID);
            
            ShoppingCart tempCart = new ShoppingCart();

            var writeThisAsHtml = "<table>";
            writeThisAsHtml += "<tr><td>Item Name</td><td>Description</td><td>Price</td></tr>";
            foreach (string productID in data.products)
            {
                var item = MVCSiteJDG.Dao.DataAccess.Reader.readProduct(productID);
                
                writeThisAsHtml += "<tr><td>"+item[0]+"</td><td>"+item[1]+"</td><td>"+item[2]+"</td></tr>";
            }
            writeThisAsHtml += "</table>";
            return writeThisAsHtml;

        }
        

    }

}

